clear all

use Master2018.dta

sort date 

set matsize 5000

replace both_overall = both_overall[_n-1] if missing(both_overall)

egen firstdate_break = min(date) if bothinbreak == 1, by(both_overall)
label var firstdate "Date of start of Break"

egen lastdate_break = max(date) if bothinbreak == 1 , by(both_overall)
label var lastdate "Date of end of Break"

gen day_break = date - firstdate_break
label var day_break "Number of days from start of break"
gen prop_day_break = day_break / (lastdate_break - firstdate_break)
label var prop_day_break "Proportion of time to the end of the break"


egen firstdate_session = min(date) if bothinsession == 1 , by(both_overall)
replace firstdate_session = l.firstdate_session if firstdate_session >= .
label var firstdate_session "Date of start of Session"

egen lastdate_session = max(date) if bothinsession ==1 , by(both_overall)
replace lastdate_session = l.lastdate_session if lastdate_session >=.
label var lastdate_session "Date of end of Session"

gen session_length = lastdate_session - firstdate_session
label var session_length "Total days of overall session"

gen break_length = lastdate_break - firstdate_break
label var break_length "Total days of break"

label var LegisMaj "Majority"
label var LSmaj "LS Majority"

label var yr_bef_elec "Yr before  election"
label var effectpartvote "Effective num parties"
label var cong_govt "Congress govt"
label var date "Linear time trend"

drop if bothinsession == 1
sort prop_day_break

gen day_break_100 = day_break / 100
drop day_break
rename day_break_100 day_break
label var day_break "Days from start of break / 100"

program drregx, eclass
	version 14
	syntax varlist(min=2 fv) [if] [in], robust [Test(string)] [*]
	reg `varlist' `if' `in', robust `options'
	if "`test'" != "" {
		test `test'
		ereturn local test_cmd `test'
		ereturn scalar test_p = r(p)
	}
end

local session_ctls "break_length session_length i.sessionwithinloksabha"
local pol_ctls "yr_bef_elec effectpartvote cong_govt"

// The next 8 lines replicate the regressions in Table 8 from the paper
eststo timing_1: drregx ordinances LegisMaj day_break c.day_break#c.LegisMaj, robust test(day_break + day_break#c.LegisMaj = 0)
eststo timing_2: drregx ordinances LegisMaj day_break c.day_break#c.LegisMaj i.month_id, robust test(day_break + day_break#c.LegisMaj = 0)
eststo timing_3: drregx ordinances LegisMaj day_break c.day_break#c.LegisMaj i.month_id i.day_id, robust test(day_break + day_break#c.LegisMaj = 0)
eststo timing_4: drregx ordinances LegisMaj day_break c.day_break#c.LegisMaj `session_ctls' i.month_id i.day_id, robust test(day_break + day_break#c.LegisMaj = 0)
eststo timing_5: drregx ordinances LegisMaj day_break c.day_break#c.LegisMaj `session_ctls' `pol_ctls' i.month_id i.day_id, robust test(day_break + day_break#c.LegisMaj = 0)
eststo timing_6: drregx ordinances LegisMaj day_break c.day_break#c.LegisMaj `session_ctls' yr_bef_elec i.month_id i.day_id i.loksabhainsession, robust test(day_break + day_break#c.LegisMaj = 0)
eststo timing_7: drregx ordinances LegisMaj day_break c.day_break#c.LegisMaj `session_ctls' yr_bef_elec i.month_id i.day_id i.year, robust test(day_break + day_break#c.LegisMaj = 0)
eststo timing_8: drregx ordinances 			day_break c.day_break#c.LegisMaj i.day_id i.both_overall, robust test(day_break + day_break#c.LegisMaj = 0)


eststo LS_timing_1: drregx ordinances LSmaj day_break c.day_break#c.LSmaj, robust test(day_break + day_break#c.LSmaj = 0)
eststo LS_timing_2: drregx ordinances LSmaj day_break c.day_break#c.LSmaj i.month_id, robust test(day_break + day_break#c.LSmaj = 0)
eststo LS_timing_3: drregx ordinances LSmaj day_break c.day_break#c.LSmaj i.month_id i.day_id, robust test(day_break + day_break#c.LSmaj = 0)
eststo LS_timing_4: drregx ordinances LSmaj day_break c.day_break#c.LSmaj `session_ctls' i.month_id i.day_id, robust test(day_break + day_break#c.LSmaj = 0)
eststo LS_timing_5: drregx ordinances LSmaj day_break c.day_break#c.LSmaj `session_ctls' `pol_ctls' i.month_id i.day_id, robust test(day_break + day_break#c.LSmaj = 0)
eststo LS_timing_6: drregx ordinances LSmaj	day_break c.day_break#c.LSmaj `session_ctls' yr_bef_elec i.month_id i.day_id i.loksabhainsession, robust test(day_break + day_break#c.LSmaj = 0)
eststo LS_timing_7: drregx ordinances LSmaj	day_break c.day_break#c.LSmaj `session_ctls' yr_bef_elec i.month_id i.day_id i.year, robust test(day_break + day_break#c.LSmaj = 0)
eststo LS_timing_8: drregx ordinances 			day_break c.day_break#c.LSmaj i.day_id i.both_overall, robust test(day_break + day_break#c.LSmaj = 0)

gen atleast1_ord = 0
replace atleast1_ord = 1 if ordinances > 0

eststo ord_timing_1: drregx atleast1_ord LegisMaj day_break c.day_break#c.LegisMaj, robust test(day_break + day_break#c.LegisMaj = 0)
eststo ord_timing_2: drregx atleast1_ord LegisMaj day_break c.day_break#c.LegisMaj i.month_id, robust test(day_break + day_break#c.LegisMaj = 0)
eststo ord_timing_3: drregx atleast1_ord LegisMaj day_break c.day_break#c.LegisMaj i.month_id i.day_id, robust test(day_break + day_break#c.LegisMaj = 0)
eststo ord_timing_4: drregx atleast1_ord LegisMaj day_break c.day_break#c.LegisMaj `session_ctls' i.month_id i.day_id, robust test(day_break + day_break#c.LegisMaj = 0)
eststo ord_timing_5: drregx atleast1_ord LegisMaj day_break c.day_break#c.LegisMaj `session_ctls' `pol_ctls' i.month_id i.day_id, robust test(day_break + day_break#c.LegisMaj = 0)
eststo ord_timing_6: drregx atleast1_ord LegisMaj	day_break c.day_break#c.LegisMaj `session_ctls' yr_bef_elec i.month_id i.day_id i.loksabhainsession, robust test(day_break + day_break#c.LegisMaj = 0)
eststo ord_timing_7: drregx atleast1_ord LegisMaj	day_break c.day_break#c.LegisMaj `session_ctls' yr_bef_elec i.month_id i.day_id i.year, robust test(day_break + day_break#c.LegisMaj = 0)
eststo ord_timing_8: drregx atleast1_ord 			day_break c.day_break#c.LegisMaj i.day_id i.both_overall, robust test(day_break + day_break#c.LegisMaj = 0)


eststo LS_ord_timing_1: drregx atleast1_ord LSmaj day_break c.day_break#c.LSmaj, robust test(day_break + day_break#c.LSmaj = 0)
eststo LS_ord_timing_2: drregx atleast1_ord LSmaj day_break c.day_break#c.LSmaj i.month_id, robust test(day_break + day_break#c.LSmaj = 0)
eststo LS_ord_timing_3: drregx atleast1_ord LSmaj day_break c.day_break#c.LSmaj i.month_id i.day_id, robust test(day_break + day_break#c.LSmaj = 0)
eststo LS_ord_timing_4: drregx atleast1_ord LSmaj day_break c.day_break#c.LSmaj `session_ctls' i.month_id i.day_id, robust test(day_break + day_break#c.LSmaj = 0)
eststo LS_ord_timing_5: drregx atleast1_ord LSmaj day_break c.day_break#c.LSmaj `session_ctls' `pol_ctls' i.month_id i.day_id, robust test(day_break + day_break#c.LSmaj = 0)
eststo LS_ord_timing_6: drregx atleast1_ord LSmaj day_break c.day_break#c.LSmaj `session_ctls' yr_bef_elec i.month_id i.day_id i.loksabhainsession, robust test(day_break + day_break#c.LSmaj = 0)
eststo LS_ord_timing_7: drregx atleast1_ord LSmaj day_break c.day_break#c.LSmaj `session_ctls' yr_bef_elec i.month_id i.day_id i.year, robust test(day_break + day_break#c.LSmaj = 0)
eststo LS_ord_timing_8: drregx atleast1_ord 	  day_break c.day_break#c.LSmaj i.day_id i.both_overall, robust test(day_break + day_break#c.LSmaj = 0)

program nbregx, eclass
	version 14
	syntax varlist(min=2 fv) [if] [in], robust [Test(string)] [*]
	nbreg `varlist' `if' `in', robust `options'
	if "`test'" != "" {
		test `test'
		ereturn local test_cmd `test'
		ereturn scalar test_p = r(p)
	}
end



eststo nb_timing_1: nbregx ordinances LegisMaj day_break c.day_break#c.LegisMaj, robust test(day_break + day_break#c.LegisMaj = 0)
eststo nb_timing_2: nbregx ordinances LegisMaj day_break c.day_break#c.LegisMaj i.month_id, robust test(day_break + day_break#c.LegisMaj = 0)
eststo nb_timing_3: nbregx ordinances LegisMaj day_break c.day_break#c.LegisMaj i.month_id i.day_id, robust test(day_break + day_break#c.LegisMaj = 0)
eststo nb_timing_4: nbregx ordinances LegisMaj day_break c.day_break#c.LegisMaj `session_ctls' i.month_id i.day_id, robust test(day_break + day_break#c.LegisMaj = 0)
eststo nb_timing_5: nbregx ordinances LegisMaj day_break c.day_break#c.LegisMaj `session_ctls' `pol_ctls' i.month_id i.day_id, robust test(day_break + day_break#c.LegisMaj = 0)
eststo nb_timing_6: nbregx ordinances LegisMaj day_break c.day_break#c.LegisMaj `session_ctls' yr_bef_elec i.month_id i.day_id i.loksabhainsession, robust test(day_break + day_break#c.LegisMaj = 0)
eststo nb_timing_7: nbregx ordinances LegisMaj day_break c.day_break#c.LegisMaj `session_ctls' yr_bef_elec i.month_id i.day_id i.year, robust test(day_break + day_break#c.LegisMaj = 0)
eststo nb_timing_8: nbregx ordinances 		   day_break c.day_break#c.LegisMaj i.day_id i.both_overall, robust test(day_break + day_break#c.LegisMaj = 0)


eststo LS_nb_timing_1: nbregx ordinances LSmaj day_break c.day_break#c.LSmaj, robust test(day_break + day_break#c.LSmaj = 0)
eststo LS_nb_timing_2: nbregx ordinances LSmaj day_break c.day_break#c.LSmaj i.month_id, robust test(day_break + day_break#c.LSmaj = 0)
eststo LS_nb_timing_3: nbregx ordinances LSmaj day_break c.day_break#c.LSmaj i.month_id i.day_id, robust test(day_break + day_break#c.LSmaj = 0)
eststo LS_nb_timing_4: nbregx ordinances LSmaj day_break c.day_break#c.LSmaj `session_ctls' i.month_id i.day_id, robust test(day_break + day_break#c.LSmaj = 0)
eststo LS_nb_timing_5: nbregx ordinances LSmaj day_break c.day_break#c.LSmaj `session_ctls' `pol_ctls' i.month_id i.day_id, robust test(day_break + day_break#c.LSmaj = 0)
eststo LS_nb_timing_6: nbregx ordinances LSmaj day_break c.day_break#c.LSmaj `session_ctls' yr_bef_elec i.month_id i.day_id i.loksabhainsession, robust test(day_break + day_break#c.LSmaj = 0)
eststo LS_nb_timing_7: nbregx ordinances LSmaj day_break c.day_break#c.LSmaj `session_ctls' yr_bef_elec i.month_id i.day_id i.year, robust test(day_break + day_break#c.LSmaj = 0)
eststo LS_nb_timing_8: nbregx ordinances 	   day_break c.day_break#c.LSmaj i.day_id i.both_overall, robust test(day_break + day_break#c.LSmaj = 0)


#delimit ;
local common_tab_opts
star(* 0.1 ** 0.05 *** 0.01)
varwidth(30) modelwidth(10) wrap se r2 nobase noomitted
label numbers nodepvars
;
#delimit cr


local year_and_ls		`common_tab_opts' indicate("Month dummies = *.month_id" "Day of week dummies = *.day_id" "Session controls = break_length session_length *.sessionwithinloksabha" "Lok Sabha dummies = *.loksabhainsession" "Year dummies = *.year" "Overall session dummies = *.both_overall")

esttab timing_* 		, `year_and_ls' nomtitles scalar("test_p \$p\$-value \$H_0: \beta_A + \lambda = 0\$" ) sfmt(3) replace
esttab ord_timing_* 	, `year_and_ls' nomtitles scalar("test_p \$p\$-value \$H_0: \beta_A + \lambda = 0\$" ) sfmt(3) replace
esttab nb_timing_* 		, `year_and_ls' noconstant nomtitles scalar("test_p \$p\$-value \$H_0: \beta_A + \lambda = 0\$" ) sfmt(3) replace

esttab LS_timing_* 		, `year_and_ls' nomtitles scalar("test_p \$p\$-value \$H_0: \beta_A + \lambda = 0\$" ) sfmt(3) replace
esttab LS_ord_timing_* 	, `year_and_ls' nomtitles scalar("test_p \$p\$-value \$H_0: \beta_A + \lambda = 0\$" ) sfmt(3) replace
esttab LS_nb_timing_* 	, `year_and_ls' noconstant nomtitles scalar("test_p \$p\$-value \$H_0: \beta_A + \lambda = 0\$" ) sfmt(3) replace



esttab timing_* 		using "tables/timing.tex"		, `year_and_ls' nomtitles scalar("test_p \$p\$-value \$H_0: \beta_A + \lambda = 0\$" ) substitute(\_ _) sfmt(3) replace
esttab ord_timing_* 	using "tables/ord_timing.tex"	, `year_and_ls' nomtitles scalar("test_p \$p\$-value \$H_0: \beta_A + \lambda = 0\$" ) substitute(\_ _) sfmt(3) replace
esttab nb_timing_* 		using "tables/nb_timing.tex"	, `year_and_ls' noconstant nomtitles scalar("test_p \$p\$-value \$H_0: \beta_A + \lambda = 0\$" ) substitute(\_ _) sfmt(3) replace

esttab LS_timing_* 		using "tables/LS_timing.tex"	, `year_and_ls' nomtitles scalar("test_p \$p\$-value \$H_0: \beta_A + \lambda = 0\$" ) substitute(\_ _) sfmt(3) replace
esttab LS_ord_timing_* 	using "tables/LS_ord_timing.tex", `year_and_ls' nomtitles scalar("test_p \$p\$-value \$H_0: \beta_A + \lambda = 0\$" ) substitute(\_ _) sfmt(3) replace
esttab LS_nb_timing_* 	using "tables/LS_nb_timing.tex"	, `year_and_ls' noconstant nomtitles scalar("test_p \$p\$-value \$H_0: \beta_A + \lambda = 0\$" ) substitute(\_ _) sfmt(3) replace





